﻿@model PagedCollection<Article>
@{
    ViewBag.Title = "文章管理";
}
<a asp-action="Edit" class="btn btn-primary mb-3"><i class="fa fa-plus"></i> 新增文章</a>
<table class="table table-hover">
    <thead class="thead-light">
        <tr>
            <th width="60px">编号</th>
            <th width="60px">排序</th>
            <th>分类</th>
            <th>标题</th>
            <th>阅读量</th>
            <th>创建时间</th>
            <th>是否推荐</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @if (!Model.Any())
        {
            <tr>
                <td colspan="5" class="text-center text-muted">暂无任何数据</td>
            </tr>

        }
        @foreach (var item in Model)
        {
            <tr>
                <td>@item.Id</td>
                <td>@item.DisplayOrder</td>
                <td>
                    <a asp-page="/List" asp-route-categoryId="@item.CategoryId" target="_blank">
                        @item.Category.Name
                    </a>
                </td>
                <td>
                    <a href="/detail/@item.Id" target="_blank">
                        @item.Title
                    </a>
                </td>
                <td>@item.ViewCount</td>
                <td>@item.CreateTime</td>
                <td>@item.IsRecommand.ToTrueFalseBadge()</td>
                <td>
                    <a asp-action="Edit" asp-route-id="@item.Id"><i class="fa fa-edit"></i> 编辑</a>
                    <a href="javascript:remove('@item.Id');"><i class="fa fa-trash"></i> 删除</a>
                </td>
            </tr>
        }
    </tbody>
</table>
    @Html.Pagination(Model, new PageButtonOptions { AlwaysShow = true, HtmlAttributes = new { @class = " justify-content-center" } })
@section scripts{
    <script type="text/javascript">
        function remove (id){
            if (confirm('确定删除吗？')) {
                $.ajax({
                    url: '@Url.Action("Delete")',
                    method: 'post',
                    data: { id: id },
                    success: function () {
                        location.reload();
                    },
                    error: function (data) {
                        alert(data.responseText);
                    }
                });
            }
        }
    </script>
}